package com.mpyy.handler.sales;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.*;
import com.mpyy.service.sales.SellSalesReturnQueryServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Descrioption SellSalesReturnQueryController
 * @Author QIAO
 * @Date 2022-03-12 8:27
 */
@Controller
public class SellSalesReturnQueryController {
    @Autowired
    @Qualifier(value = "sellSalesReturnQueryServiceImpl")
    private SellSalesReturnQueryServiceInter sellSalesReturnQueryServiceInter;


    /**
     *查询销售退货查询的上部分表格数据
     * @param request
     * @param saleOrderAndSaleReturn
     * @return
     */
    @RequestMapping(value = {"/showSalesReturnQueryOrderDatas"})
    @ResponseBody
    public String showSalesReturnQueryOrderDatas(HttpServletRequest request , SaleOrderAndSaleReturn saleOrderAndSaleReturn){

        String orsalOrdId= request.getParameter("orsalOrdId");
        saleOrderAndSaleReturn.setOrsalOrdId(orsalOrdId);

        String currentTimeStart= request.getParameter("currentTimeStart");

        String currentTimeEnd= request.getParameter("currentTimeEnd");

        String ordepotName= request.getParameter("ordepotName");

        String orempName= request.getParameter("orempName");

        int total =sellSalesReturnQueryServiceInter.salesReturnQueryOrder(null).size();

        List<SaleOrderAndSaleReturn> saleOrderAndSaleReturnList=sellSalesReturnQueryServiceInter.salesReturnQueryOrder(saleOrderAndSaleReturn);


        Map<String , Object> map = new HashMap<>();
        map.put("code" , 0);
        map.put("msg","");
        map.put("count" , total);
        map.put("data" , saleOrderAndSaleReturnList);

        String saleOrderAndSaleReturnJosnStr= JSON.toJSONString(map);
        return saleOrderAndSaleReturnJosnStr;
    }

    /**
     * 查询单据的详细信息
     * @param request
     * @param saleOrderDescAndSaleReturn
     * @return
     */
    @RequestMapping(value = {"/showSalesDescDataDatas"})
    @ResponseBody
    public String showSalesDescDataDatas(HttpServletRequest request , SaleOrderDescAndSaleReturn saleOrderDescAndSaleReturn){

        int total =sellSalesReturnQueryServiceInter.salesDescData(null).size();

        List<SaleOrderDescAndSaleReturn> saleOrderDescAndSaleReturnList=sellSalesReturnQueryServiceInter.salesDescData(saleOrderDescAndSaleReturn);


        Map<String , Object> map = new HashMap<>();
        map.put("code" , 0);
        map.put("msg","");
        map.put("count" , total);
        map.put("data" , saleOrderDescAndSaleReturnList);

        String salesDescDataJosnStr= JSON.toJSONString(map);
        return salesDescDataJosnStr;
    }

    /**
     * 查询客户名称
     * @return
     */
    @RequestMapping(value = {"/selectCustName"} ,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String selectCustName(){
        List<CustomerInfo> customerInfos = sellSalesReturnQueryServiceInter.selectCustName();
        String customerInfosList= JSON.toJSONString(customerInfos);
        return customerInfosList;
    }

    /**
     * 查询操作员
     * @return
     */
    @RequestMapping(value = {"/selectEmpName"} ,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String selectEmpName(){
        List<EmployeeInfo> employeeInfos = sellSalesReturnQueryServiceInter.selectEmpName();
        String employeeInfosList= JSON.toJSONString(employeeInfos);
        return employeeInfosList;
    }

    /**
     * 查询仓库名称
     * @return
     */
    @RequestMapping(value = {"/selectDepName"} ,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String selectDepName(){
        List<DepotInfo> depotInfos = sellSalesReturnQueryServiceInter.selectDepName();
        String depotInfosList= JSON.toJSONString(depotInfos);
        return depotInfosList;
    }
}
